home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / tools / Explosives.lua < prev    next >
Text File  |  2010-09-16  |  4KB  |  122 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Explosives
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2010, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.explosives={}
  10. cc.explosives.expl={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.explosives.sfx_attack=loadsfx("throw.ogg")                                        -- Attack Sound
  14. cc.explosives.sfx_bounce=loadsfx("bounce.wav")                                        -- Bounce
  15. cc.explosives.gfx_wpn=loadgfx("buildings/explosives.bmp")
  16. setmidhandle(cc.explosives.gfx_wpn)
  17.  
  18. --------------------------------------------------------------------------------
  19. -- Weapon: Explosives
  20. --------------------------------------------------------------------------------
  21.  
  22. cc.explosives.id=addweapon("cc.explosives","Explosives",cc.explosives.gfx_wpn,1,2)    -- Add Weapon (1 use, first in round 2)
  23.  
  24. function cc.explosives.draw()                                                        -- Draw
  25.     -- HUD Positioning
  26.     if weapon_shots==0 then
  27.         hudpositioning(pos_build,cc.explosives.gfx_wpn,30,1,1,1)
  28.     end
  29. end
  30.  
  31. function cc.explosives.attack(attack)                                                -- Attack
  32.     if (weapon_shots<=0) and (weapon_position==1) then
  33.         -- No more weapon switching!
  34.         useweapon(0)
  35.         playsound(cc.explosives.sfx_attack)
  36.         weapon_shots=weapon_shots+1
  37.         createobject(cc.explosives.expl.id,weapon_x,weapon_y)
  38.         -- End Turn
  39.         endturn()
  40.     end
  41. end
  42.  
  43. --------------------------------------------------------------------------------
  44. -- Object: Explosives
  45. --------------------------------------------------------------------------------
  46.  
  47. cc.explosives.expl.id=addobject("cc.explosives.expl",cc.explosives.gfx_wpn)            -- Add Object
  48.  
  49. function cc.explosives.expl.setup(id,parameter)
  50.     if objects==nil then objects={} end
  51.     objects[id]={}
  52.     objects[id].sy=0
  53.     objects[id].timer=0
  54. end
  55.  
  56. function cc.explosives.expl.draw(id,x,y)
  57.     -- Setup draw mode
  58.     setblend(blend_alpha)
  59.     setalpha(1)
  60.     setcolor(255,255,255)
  61.     setscale(1,1)
  62.     setrotation(0)
  63.     -- Draw
  64.     drawimage(cc.explosives.gfx_wpn,x,y)
  65. end
  66.  
  67. function cc.explosives.expl.update(id,x,y)
  68.     -- Gravity influence on speed
  69.     objects[id].sy=objects[id].sy+getgravity()
  70.     -- Move (in substep loop for optimal collision precision)
  71.     msubt=math.ceil(math.abs(objects[id].sy)/15)
  72.     msuby=objects[id].sy/msubt
  73.     for i=1,msubt,1 do
  74.         y=y+msuby
  75.         -- Collision
  76.         if collision(cc.explosives.gfx_wpn,x,y,1,1,1,-1,id)==1 then
  77.             if (math.abs(objects[id].sy)>0.5) then playsound(cc.explosives.sfx_bounce) end
  78.             y=y-msuby
  79.             objects[id].sy=-objects[id].sy*0.3
  80.             msuby=-msuby*0.3
  81.         end
  82.         -- Water
  83.         if y>getwatery()+5 then
  84.             -- Effects
  85.             particle(p_waterhit,x,y)
  86.             playsound(sfx_hitwater1)
  87.             -- Remove
  88.             removeobject(id)
  89.             return
  90.         end
  91.     end
  92.     objectposition(id,x,y)
  93.     -- Explode (delayed)
  94.     if objects[id].timer>0 then
  95.         objects[id].timer=objects[id].timer+1
  96.         if objects[id].timer>=20 then
  97.             -- Destroy terrain
  98.             terrainexplosion(x,y,50,1)
  99.             -- Crater
  100.             grey=math.random(0,40)
  101.             if math.random(0,1)==1 then
  102.                 terrainalphaimage(gfx_crater125,getobjectx(id),getobjecty(id),math.random(6,9)*0.1,grey,grey,grey)
  103.             else
  104.                 terrainalphaimage(gfx_crater150,getobjectx(id),getobjecty(id),math.random(6,9)*0.1,grey,grey,grey)
  105.             end
  106.             -- Remove
  107.             removeobject(id)
  108.             -- Cause damage
  109.             arealdamage(x,y,140,80)
  110.         end
  111.     -- Fire Collision?
  112.     elseif firecollision(cc.explosives.gfx_wpn,x,y)>0 then
  113.         objects[id].timer=1
  114.     end
  115. end
  116.  
  117. function cc.explosives.expl.damage(id,damage)
  118.     if objects[id].timer==0 then 
  119.         objects[id].timer=1
  120.     end
  121. end
  122.